package gen.tools;

import java.io.IOException;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class UpdateSpecificSysParameter extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    public UpdateSpecificSysParameter() {
        super();
    }

	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doPost(request,response);
	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		
		final Widgets wid = new Widgets();
		request.setCharacterEncoding( wid.UIcodeSet );
		response.setCharacterEncoding( wid.UIcodeSet );
		response.setContentType("application/text");
		
		String res= "fail";
		
		Connection conn = null;
		PreparedStatement ps = null;
		ResultSet rs = null;
		final String pn = request.getParameter("pn");
		final String pv = request.getParameter("pv");
		String sql = "UPDATE configparameter SET paraVal=? WHERE paraName=?";
		
		try {
			conn = wid.getConn();
			//處理部署執行主檔
			ps = conn.prepareStatement(sql);
			ps.setString(1, pv);
			ps.setString(2, pn);
			ps.execute();
			res= "OK";
		} catch(Exception e) {
			wid.errLog(e);
		} finally {
			try {
				if ( rs !=null ) { rs.close(); }
				if ( ps !=null ) { ps.close(); }
				if ( conn !=null ) { conn.close(); }
			} catch (Exception e) { e.printStackTrace(); }
		}
		
		response.getWriter().write(res);
	}
}
